<?php
// include function files for this application
require_once('/home/domains/uny-con.com/public_html/uny-con_fns.php');
if (!session_id()) { session_start(); }


//This is an admin only script so first lets check to make sure the user is valid and an admin. then we can do toher stuff.

if (!check_valid_user() || ($_SESSION['admin'] != 't')) {
	do_html_header('Unauthorized access', gobig, $uny);
	echo 'You are not logged in or are not authorized to view this page. Please move along.';
	print_brs(6);
	do_html_footer(news);
	exit;
	}

	do_html_header('Room Report', gobig, $uny);

if (!($conn = db_connect())) return false;

$rooms = pg_query("select room_name, '' AS ts0, '' AS ts1, '' AS ts2, '' AS ts3, '' AS ts4, '' AS ts5, '' AS ts6, '' AS ts7, '' AS ts8, '' AS ts9, '' AS ts10, '' AS ts11
from rooms
order by room_name ASC");

$max_rooms = pg_num_rows($rooms);
$room_array = pg_fetch_all($rooms);
//$max_rooms = pg_query("select count(*) from rooms");

for ($ts = 0; $ts <= 11; $ts++){
	$ts_query = pg_query("select assigned_room, event_id, start_time
	from event_time
	where start_time = $ts;");

	$ts_array = pg_fetch_all($ts_query);


	for ($i = 0; $i < $max_rooms; $i++) {
		foreach ($ts_array as $ts_row) {
			$timeslot = "ts".$ts;
			if ($ts_row[assigned_room] == $room_array[$i][room_name]){ 
				$room_array[$i][$timeslot] = 'X';
				break; 
			}
		}
	}		
}		

echo "<h1>Current Assigned Rooms</h1>\n";
echo "\t<ul class=\"plainul\">\n";

//trying to do an output table:
	echo "<table>\n";
	echo "	<tr class=\"grey_back\">\n";
	echo "		<th class=\"eventlist\"><strong>Room Name</strong></th>\n";
	echo "		<th class=\"eventlist\"><strong>Time Slot 0</strong></th>\n";
	echo "		<th class=\"eventlist\"><strong>Time Slot 1</strong></th>\n";
	echo "		<th class=\"eventlist\"><strong>Time Slot 2</strong></th>\n";
	echo "		<th class=\"eventlist\"><strong>Time Slot 3</strong></th>\n";
	echo "		<th class=\"eventlist\"><strong>Time Slot 4</strong></th>\n";
	echo "		<th class=\"eventlist\"><strong>Time Slot 5</strong></th>\n";
	echo "		<th class=\"eventlist\"><strong>Time Slot 6</strong></th>\n";
	echo "		<th class=\"eventlist\"><strong>Time Slot 7</strong></th>\n";
	echo "		<th class=\"eventlist\"><strong>Time Slot 8</strong></th>\n";
	echo "		<th class=\"eventlist\"><strong>Time Slot 9</strong></th>\n";
	echo "		<th class=\"eventlist\"><strong>Time Slot 10</strong></th>\n";
	echo "		<th class=\"eventlist\"><strong>Time Slot 11</strong></th>\n";
	echo "	</tr>\n";
	$i = 0;
	
foreach ($room_array as $row) {
//		extract($row);
//		extract($room_row);
//		$current_room = $room_name;
//print each row
		echo "	<tr$greyback>\n";
		echo "		<td class=\"eventlist\">$row[room_name]</td>\n";
		echo "		<td class=\"eventlist\">$row[ts0]</td>\n";		
		echo "		<td class=\"eventlist\">$row[ts1]</td>\n";
		echo "		<td class=\"eventlist\">$row[ts0]</td>\n";	
		echo "		<td class=\"eventlist\">$row[ts3]</td>\n";
		echo "		<td class=\"eventlist\">$row[ts4]</td>\n";
		echo "		<td class=\"eventlist\">$row[ts5]</td>\n";
		echo "		<td class=\"eventlist\">$row[ts6]</td>\n";
		echo "		<td class=\"eventlist\">$row[ts7]</td>\n";
		echo "		<td class=\"eventlist\">$row[ts8]</td>\n";
		echo "		<td class=\"eventlist\">$row[ts9]</td>\n";
		echo "		<td class=\"eventlist\">$row[ts10]</td>\n";
		echo "		<td class=\"eventlist\">$row[ts11]</td>\n";
		echo "	</tr>\n";

		if (oddeven($i) == 'even') $greyback = " class=\"grey_back\"";
		if (oddeven($i) == 'odd') $greyback = "";
		$i++;
	}
echo '</ul>';



do_html_footer(no_news);